package com.runner.screen;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.runner.utility.Constants;
import com.runner.utility.Locator;

public class BackgroundManager implements Constants{

	private Texture background, background2;
	private float position, position2;
	public float SPEED=60f;
	
	public BackgroundManager(){
		background=Locator.getAssets().get(BACKGROUNDMAIN_RINGER, Texture.class);
		background2=Locator.getAssets().get(BACKGROUNDMAIN_RINGER, Texture.class);
		position=0;
		position2=ACTUAL_VIRTUAL_WIDTH;
	}
	
	public void updateBackground(PLAYER_TYPE pType){
		switch(pType){
		case RINGER:
			background=Locator.getAssets().get(BACKGROUNDMAIN_RINGER, Texture.class);
			background2=Locator.getAssets().get(BACKGROUNDMAIN_RINGER, Texture.class);
			break;
		case APRIL:
			background=Locator.getAssets().get(BACKGROUNDMAIN_APRIL, Texture.class);
			background2=Locator.getAssets().get(BACKGROUNDMAIN_APRIL, Texture.class);
			break;
		case GEO:
			background=Locator.getAssets().get(BACKGROUNDMAIN_GEO, Texture.class);
			background2=Locator.getAssets().get(BACKGROUNDMAIN_GEO, Texture.class);
			break;
		}
	}
	
	public void render(SpriteBatch uiBatch){
		uiBatch.draw(background, position, 0, 0, 0, background.getWidth(), background.getHeight(), Locator.getxSpriteScale(), Locator.getySpriteScale(), 0,
				0, 0, (int) background.getWidth(), (int) background.getHeight(), false, false);
		uiBatch.draw(background2, position2, 0, 0, 0, background.getWidth(), background.getHeight(), Locator.getxSpriteScale(), Locator.getySpriteScale(), 0,
				0, 0, (int) background.getWidth(), (int) background.getHeight(), false, false);
	}
	
	public void update(float delta){
		position-=SPEED*Locator.getXGameSpeed()*delta;
		position2-=SPEED*Locator.getXGameSpeed()*delta;
		if(position <= -ACTUAL_VIRTUAL_WIDTH){
			position=ACTUAL_VIRTUAL_WIDTH;
		}
		if(position2 <= -ACTUAL_VIRTUAL_WIDTH){
			position2=ACTUAL_VIRTUAL_WIDTH;
		}
	}
	
	public void reset(){
		position=0;
		position2=ACTUAL_VIRTUAL_WIDTH;
	}
}
